﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;
using FukiERP.Common.Constants;
using FukiERP.Common.DTO;
using FukiERP.Helper;
using FukiERP.Services.DBContext;
using FukiERP.Services.Helper;


namespace FukiERP.Report
{
    public partial class SellingReportForm : Telerik.WinControls.UI.RadForm
    {
        public SellingReportForm()
        {
            InitializeComponent();
        }

        private void SellingReportForm_Load(object sender, EventArgs e) {
            FukiERPDataContext context = DataAccess.GetDBContext();
            _dtpFrom.Value = DateTime.Today.AddDays(-1);
            _dtpTo.Value = DateTime.Today;
        }

        private void _btnViewReport_Click(object sender, EventArgs e) {
            FukiERPDataContext context = DataAccess.GetDBContext();
            _grdSellingOrder.DataSource = null;
            _grdSellingInfo.DataSource = null;
            _grdSellingOrder.DataSource = context.view_GetSellingInfos.Where( c => c.Date.Date >= _dtpFrom.Value.Date &&
                c.Date.Date <= _dtpTo.Value.Date).OrderBy(c => c.Date).ThenBy(c => c.Saler).ToList();
        }

        private void _grdSellingOrder_CellDoubleClick(object sender, GridViewCellEventArgs e) {
            int currentSellingOrderId = int.Parse(_grdSellingOrder.Rows[e.RowIndex].Cells[0].Value.ToString());
            FukiERPDataContext context = DataAccess.GetDBContext();
            _grdSellingInfo.DataSource = null;
            _grdSellingInfo.DataSource = context.View_SellingInfos.
                Where(c => c.SellingOrderID == currentSellingOrderId).ToList();
        }
    }
}
